import time

from selenium.webdriver.common.by import By

from base.page_base import BasePage


class Testloanmanagement(BasePage):
    loan = (By.LINK_TEXT, '借款管理')  # 顶第一步
    quota = (By.XPATH, '//*[text()="额度管理"]')  # 点击第左一步
    review = (By.XPATH, '//*[@id="sidebar"]/ul/li[5]/ul/li[2]/a')  # 点击左二步
    fr_ele = (By.ID, 'iframe_box')
    username = By.NAME, 'member_name'  # 用户名  #
    search_btn = By.CSS_SELECTOR, '[value="搜索"]'  #
    click_review = (By.XPATH, '//tbody/tr[1]/td[2]/span')  # 选择人
    click_review_01 = (By.XPATH, '/html/body/div[2]/div[2]/ul/li[1]/a/span')  # 点击审核
    # fff = (By.XPATH, '//*[@id="xubox_iframe1"]')
    __frame2 = (By.CSS_SELECTOR, "#xubox_iframe1")
    __radio = By.CSS_SELECTOR, '.ace.ng-pristine.ng-untouched.ng-valid'  # 通过
    click_review_02 = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[5]/td[2]/div/label[1]')  # 点击同意
    note = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[6]/td[2]/div/textarea')  # 输入备注
    yzm = (By.NAME, 'valicode')  # 输入验证码
    save = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[8]/td[2]/input[1]')  # 点击保存
    #  断言
    __app_rec = (By.LINK_TEXT, "额度申请记录")  # 额度申请记录
    # 搜索：用户名 + 状态 + 搜索按钮
    __app_status = By.CSS_SELECTOR, "select[name='status']"  # 状态
    # 审核列表状态：通过
    __rec_list = By.CSS_SELECTOR, "tbody > tr:nth-child(1) > td.status > span"

    def click_menu_manage(self):
        """点击管理菜单"""
        self.base_click(self.loan)
        self.base_click(self.quota)
        self.base_click(self.review)

    def search_record(self,phone):
        """搜索记录"""
        self.base_switch_frame(self.fr_ele)
        self.base_input(self.username,phone)
        self.base_click(self.search_btn)

    def click_record(self):
        """点击记录"""
        time.sleep(2)
        self.base_click(self.click_review)
        self.base_click(self.click_review_01)

    def approve_loan(self,note='666',yzm='8888'):
        """审核操作"""
        self.base_switch_frame(self.__frame2)
        # self.base_click(self.__radio)  # 单选框：通过
        self.base_click_special(self.__radio)  # 单选框：通过
        self.base_input(self.note, note)  # 备注
        self.base_input(self.yzm, yzm)  # 验证码
        self.base_click(self.save)

    def click_app_rec(self,phone, status='通过'):
        """点击额度申请记录"""
        self.base_default_frame()
        self.base_click(self.__app_rec)
        self.base_switch_frame(self.fr_ele)
        self.base_input(self.username, phone)
        self.base_select_list(self.__app_status,status)
        self.base_click(self.search_btn)

    def get_result_text(self):
        """获取审核结果"""
        time.sleep(1)  # 页面刷新，看到新记录
        return self.fd_element(self.__rec_list).text

    def credit_application_review(self,phone,note="审核OK", img_code="8888"):
        self.click_menu_manage()
        self.search_record(phone)
        self.click_record()
        self.approve_loan(note,img_code)
    # def loan_01(self):
    #     self.base_click(self.loan)
    #
    # def quota_01(self):
    #     self.base_click(self.quota)
    #
    # def review_01(self):
    #     self.base_click(self.review)
    #
    # def fr_ele_01(self):
    #     self.base_switch_frame(self.fr_ele)  #
    #
    # def username_01(self, username):
    #     self.base_input(self.username, username)
    #
    # def click_review_001(self):
    #     self.base_click(self.click_review)
    #
    # def search_btn_01(self):
    #     self.base_click(self.search_btn)
    #
    # def click_review_002(self):
    #     self.base_click(self.click_review_01)
    #
    # def cut_new_frone(self):
    #     self.base_switch_frame(self.fff)
    #
    # def click_anniu(self):
    #     self.base_click(self.click_review_02)
    #
    # def note_01(self, note):
    #     self.base_input(self.note, note)
    #
    # def yzm_01(self, yzm):
    #     self.base_input(self.yzm, yzm)
    #
    # def save_01(self):
    #     self.base_click(self.save)
    #
    # #  断言
    # def app_rec_01(self):
    #     self.base_click(self.__app_rec) #
    #
    # def app_rec_03(self):
    #     self.base_switch_frame(self.fr_ele)
    #
    # def app_rec_04(self,phone):
    #     self.base_input(self.username,phone)
    #
    # def app_rec_05(self,status='通过'):
    #     self.base_select_list(self.__app_status, status)
    #
    # def rec_list(self):
    #     self.base_click(self.search_btn)
    #
    # def audit_credit(self, username, note='1111', yzm='8888'):
    #     self.loan_01()
    #     self.quota_01()
    #     self.review_01()
    #     self.fr_ele_01()
    #     self.username_01(username)
    #     self.search_btn_01()
    #     time.sleep(1)
    #     self.click_review_001()
    #     self.click_review_002()
    #     self.cut_new_frone()
    #     self.click_anniu()
    #     self.note_01(note)
    #     self.yzm_01(yzm)
    #     self.save_01()
    #     #  断言
    #
    # def ger_result_text(self):
    #     time.sleep(2)
    #     return self.fd_element(self.__rec_list).text
    #
    # def audit_credit_01(self, username):
    #     self.base_default_frame()
    #     self.base_click(self.__app_rec)
    #     self.base_switch_frame(self.fr_ele)
    #     self.base_input(self.username, username)
